package com.qdxwx.manage.controller.my;

import com.qdxwx.common.page.PageRequest;
import com.qdxwx.common.page.TableDataInfo;
import com.qdxwx.data.service.user.UserService;

import com.qdxwx.manage.support.SessionUtils;
import com.qdxwx.models.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
@Controller
@RequestMapping("/my/user")
public class MyUserController {

    @Autowired
    private UserService userService;
    //我的课程学员
    @GetMapping("/list.html")
    public String courseUser() {
        return "my/my-user-list";
    }

    /**
     * 查询用户(我的课程学员)列表
     */
    @PostMapping("/list.json")
    @ResponseBody
    public TableDataInfo courseUser(HttpServletRequest request) {
        long userId = SessionUtils.getManager().getUserId();
        if(userId < 1) return TableDataInfo.error("登录超时");
        List<User> list = userService.getMyStudentList(userId, PageRequest.form(request));
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(userService.countMyStudent(userId));
        return rspData;
    }
}
